<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Minim : : AudioOutput : : playNote</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="stylesheet.css" rel="stylesheet" type="text/css">
</head>
<body> 
<center>
<table class="mainTable">

  <tr>
    <td class="header">
    	<span class="indexheader">Minim</span><br/>
    	<span class="indexnavigation">
    		<a href="index.html">core</a> | 
    		<a href="index_ugens.html">ugens</a> | 
    		<a href="index_analysis.html">analysis</a>
    	</span>
    </td>
    <td class="border-left">&nbsp;</td>
  </tr>
  
  <tr>
    <td class="classNavigation">
    	<p class="mainTextName"><A href="audiooutput_class_audiooutput.html">AudioOutput</A></p>
    	<p class="methodName">playNote</p>
    </td>
    <td class="mainText border-left">
    	<p class="memberSectionHeader">Description</p>
    	playNote is a method of scheduling a "note" to be played at 
 some time in the future (or immediately), where a "note" is 
 an instance of a class that implements the Instrument interface.
 The Instrument interface requires you to implement a noteOn method 
 that accepts a float duration value and is called when that 
 Instrument should begin making sound, and a noteOff method 
 that is called when that Instrument should stop making sound.
 <p>
 Versions of playNote that do not have an Instrument argument
 will create an instance of a default Instrument that plays a
 sine tone based on the parameters passed in.
 <p>
 To facilitate writing algorithmic music, the start time and 
 duration of a note is expressed in <em>beats</em> and not in seconds. 
 By default, the tempo of an AudioOutput will be 60 BPM (beats per minute), 
 which means that beats are equivalent to seconds. If you want to think 
 in seconds when writing your note playing code, then simply don't change 
 the tempo of the output.
 <p>
 Another thing to keep in mind is that the AudioOutput processes its 
 note queue in its own Thread, so if you are going to queue up a lot of 
 notes at once you will want to use the pauseNotes method before queuing
 them. If you don't, the timing will be slightly off because the "now" that
 the start time of each note is an offset from will change from note to note.
 Once all of your notes have been added, you call resumeNotes to allow 
 the AudioOutput to process notes again.
    	
    	<p class="memberSectionHeader">Signature</p>
    	<pre>void playNote(float startTime, float duration, Instrument instrument)
void playNote(float startTime, float duration, float hz)
void playNote(float startTime, float duration, String pitchName)
void playNote(float startTime, float hz)
void playNote(float startTime, String pitchName)
void playNote(float hz)
void playNote(String pitchName)
void playNote()
</pre>
    	
    	
   <p class="memberSectionHeader">Parameters</p>
   
        <span class="parameterName">startTime</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">float: when the note should begin playing, in beats</span><br/>
    
        <span class="parameterName">duration</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">float: how long the note should be, in beats</span><br/>
    
        <span class="parameterName">instrument</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">the Instrument that will play the note</span><br/>
    
        <span class="parameterName">hz</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">float: the frequency, in Hertz, of the note to be played</span><br/>
    
        <span class="parameterName">pitchName</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">String: the pitch name of the note to be played (e.g. "A4" or "Bb3")</span><br/>
    
   
    	
   <p class="memberSectionHeader">Returns</p> 
   <p>None</p>
   
    	
    	<p class="memberSectionHeader">Related</p>
    	<A href="instrument_instrument.html">Instrument</A><BR>
<A href="audiooutput_method_settempo.html">setTempo ( )</A><BR>
<A href="audiooutput_method_setnoteoffset.html">setNoteOffset ( )</A><BR>
<A href="audiooutput_method_setdurationfactor.html">setDurationFactor ( )</A><BR>
<A href="audiooutput_method_pausenotes.html">pauseNotes ( )</A><BR>
<A href="audiooutput_method_resumenotes.html">resumeNotes ( )</A><BR>

    	
    	<p class="memberSectionHeader">Example</p>
    	<pre>/**
  * This sketch demonstrates how to create synthesized sound with Minim using an &lt;code>AudioOutput&lt;/code> and the
  * default instrument built into an &lt;code>AudioOutput&lt;/code>. By using the &lt;code>playNote&lt;/code> method you can 
  * schedule notes to played at some point in the future, essentially allowing to you create musical scores with 
  * code. Because they are constructed with code, they can be either deterministic or different every time. This
  * sketch creates a deterministic score, meaning it is the same every time you run the sketch. It also demonstrates 
  * a couple different versions of the &lt;code>playNote&lt;/code> method.
  * &lt;p>
  * For more complex examples of using &lt;code>playNote&lt;/code> check out 
  * algorithmicCompExample and compositionExample in the Synthesis folder.
  * &lt;p>
  * For more information about Minim and additional features, 
  * visit http://code.compartmental.net/minim/
  */

import ddf.minim.*;
import ddf.minim.ugens.*;

Minim minim;
AudioOutput out;

void setup()
{
  size(512, 200, P3D);
  
  minim = new Minim(this);
  
  // use the getLineOut method of the Minim object to get an AudioOutput object
  out = minim.getLineOut();
  
  // set the tempo of the sequencer
  // this makes the first argument of playNote 
  // specify the start time in quarter notes
  // and the duration becomes relative to the length of a quarter note
  // by default the tempo is 60 BPM (beats per minute).
  // at 60 BPM both start time and duration can be interpreted as seconds.
  // to retrieve the current tempo, use getTempo().
  out.setTempo( 80 );
  
  // pause the sequencer so our note play back will be rock solid
  // if you don't do this, then tiny bits of error can occur since 
  // the sequencer is running in parallel with you note queueing.
  out.pauseNotes();
  
  // given start time, duration, and frequency
  out.playNote( 0.0, 0.9, 97.99 );
  out.playNote( 1.0, 0.9, 123.47 );
  
  // given start time, duration, and note name  
  out.playNote( 2.0, 2.9, "C3" );
  out.playNote( 3.0, 1.9, "E3" );
  out.playNote( 4.0, 0.9, "G3" );
    
  // given start time and note name or frequency
  // (duration defaults to 1.0)
  out.playNote( 5.0, "" );
  out.playNote( 6.0, 329.63);
  out.playNote( 7.0, "G4" );
  
  // the note offset is simply added into the start time of 
  // every subsequenct call to playNote. It's expressed in beats.
  // to get the current note offset, use getNoteOffset().
  out.setNoteOffset( 8.1 );
  
  // because only given a note name or frequency
  // starttime defaults to 0.0 and duration defaults to 1.0
  out.playNote( "G5" );
  out.playNote( 987.77 );
  
  // now we can start the sequencer again to hear our sequence
  out.resumeNotes();
}

void draw()
{
  background(0);
  stroke(255);
  
  // draw the waveforms
  for(int i = 0; i &lt; out.bufferSize() - 1; i++)
  {
    line( i, 50 + out.left.get(i)*50, i+1, 50 + out.left.get(i+1)*50 );
    line( i, 150 + out.right.get(i)*50, i+1, 150 + out.right.get(i+1)*50 );
  }
}
</pre>
    	
    	<p class="memberSectionHeader">Usage</p>
    	Web & Application
    </td>
  </tr>
</table>
</center>
</body>
</html>
